package com.kj.tms.common.bean.controller;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author:zhuyongjie
 * @Description:
 * @Date:Create in  2017/10/17 16:00
 */
public class BasicController {
    /**
     * 通过response输出字符串(响应请求)
     *
     * @param encoding
     * @param outStr
     * @param response
     */
    public void responseWrite(String encoding, String outStr, HttpServletResponse response) {
        try {
            response.setCharacterEncoding(encoding);
            PrintWriter pw = response.getWriter();
            pw.write(outStr);
            pw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 通过response输出字符串(响应请求), 编码默认是UTF-8
     *
     * @param outStr
     * @param response
     */
    public void responseWrite(String outStr, HttpServletResponse response) {
        responseWrite("UTF8", outStr, response);
    }


    /**
     * @param request
     * @return
     * @throws
     * @method getRequestParameters
     * @description [方法描述]
     * @author [zhuyongjie]
     * @version 1.0
     * @paras
     * @date 2017/10/25 18:24
     */
    public Map<String, String> getRequestParameters(HttpServletRequest request) {
        Map<String, String> map = new HashMap<String, String>();
        Enumeration enums = request.getParameterNames();
        while (enums.hasMoreElements()) {
            String paramName = (String) enums.nextElement();
            String paramValue = request.getParameter(paramName);
            if (null != paramValue && !"".equals(paramValue)) {
                map.put(paramName, paramValue);
            }
        }
        return map;
    }

   /* *//**
     * 获取登陆Session信息
     *
     * @param sessionManager
     * @return
     *//*
    public String getUserInfo(SessionManager sessionManager) {
        UserDto userSession = (UserDto) sessionManager.getAttribute(Consts.USER);
        if (StringUtil.isNull(userSession)) {
            return null;
        }
        return JsonUtils.bean2Json(userSession);
    }

    *//**
     * 获取登陆Session信息纳税主体信息
     *
     * @param sessionManager
     * @return
     *//*
    public String gettaxPayerInfo(SessionManager sessionManager) {
        List<TaxPayersInfoDto> taxPayerList = (List<TaxPayersInfoDto>) sessionManager.getAttribute(Consts.CUR_USER_ORG_TAX_PAYERS_INFO);
        if (StringUtil.isNull(taxPayerList)) {
            return null;
        }
        return JsonUtils.list2Json(taxPayerList);
    }*/
}